import {defineConfig} from "vite";
import vue from "@vitejs/plugin-vue";
import {resolve} from "path";
import vueJsxPlugin from "@vitejs/plugin-vue-jsx";
// 按需导入
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import {
    AntDesignVueResolver,
    ElementPlusResolver,
} from "unplugin-vue-components/resolvers";

const pathResolve = (dir: any) => {
    return resolve(__dirname, ".", dir);
};

const alias = {
    "@": pathResolve("./src"),
};

export default defineConfig({
    server: {
        host: "0.0.0.0", // 这个用于启动
        port: 1122, // 指定启动端口
        open: true, //启动后是否自动打开浏览器
        proxy: {
            "/api": {
                changeOrigin: true, // 开启跨域  文哥假接口
                // target: "http://localhost:8087/",
                target: "http://10.18.1.46:8087/",
                // target: "http://1f0bd62b.r12.cpolar.xyz",
                rewrite: (path) => path.replace(/^\/api/, ""),
            },
        },
    },
    root: process.cwd(),
    plugins: [
        vue(),
        vueJsxPlugin(),
        // vueDevTools(),
        // 按需导入
        AutoImport({
            imports: ["vue", "vue-router"],
            resolvers: [ElementPlusResolver()],
        }),
        Components({
            resolvers: [
                AntDesignVueResolver({
                    importStyle: false, // css in js
                }),
                ElementPlusResolver(),
            ],
        }),
    ],
    resolve: {alias},
});
